package com.kbbywyclient.ui.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.kbbywyclient.R;
import com.kbbywyclient.di.AppComponent;
import com.kbbywyclient.ui.activity.base.BaseActivity;
import com.kbbywyclient.ui.adapter.base.BaseViewPagerAdapter;
import com.kbbywyclient.ui.fragment.ApplicationRecordFragment;
import com.kbbywyclient.ui.fragment.IncomeRecordFragment;
import com.kbbywyclient.widget.CustomToolBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Jiangzx on 2017/10/31 17:06.
 */

public class MineClientActivity extends BaseActivity {
    public static final int PAGE_INCOME_RECORD=0;//收入记录
    public static final int PAGE_APPLICATION_RECORD=1;//进件记录
    @BindView(R.id.v_toolbar)
    CustomToolBar toolBar;

    @BindView(R.id.tv_income_record)
    TextView tvIncomeRecord;//收入记录
    @BindView(R.id.view_income_divider)
    View viewIncomeDivider;//收入记录分割线

    @BindView(R.id.tv_application_record)
    TextView tvApplicationRecord;//进件记录
    @BindView(R.id.view_application_divider)
    View viewApplicationDivider;//进件记录分割线

    @BindView(R.id.vp_pager)
    ViewPager viewPager;

    BaseViewPagerAdapter adapter;

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_mine_client;
    }

    @Override
    protected void initView() {
        toolBar.setLeftViewOnClickLinster(v->finish());
        setCurrentPage(PAGE_INCOME_RECORD);
        String[] titles=new String[]{getString(R.string.text_income_record),
            getString(R.string.text_application_record)};
        final List<Fragment> fragments=new ArrayList<>();
        fragments.add(new IncomeRecordFragment());
        fragments.add(new ApplicationRecordFragment());
        adapter=new BaseViewPagerAdapter(getSupportFragmentManager(),
                titles,
                fragments);
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                setCurrentPage(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        viewPager.setAdapter(adapter);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initAppComponent(AppComponent appComponent) {

    }



    private void setCurrentPage(int currentItem){
        int selectedColor=0XFF1ACBB4;
        int normalColor=0XFF999999;
        if(currentItem==PAGE_INCOME_RECORD){
            tvIncomeRecord.setTextColor(selectedColor);
            viewIncomeDivider.setVisibility(View.VISIBLE);
            tvApplicationRecord.setTextColor(normalColor);
            viewApplicationDivider.setVisibility(View.GONE);
        }else if(currentItem==PAGE_APPLICATION_RECORD){
            tvIncomeRecord.setTextColor(normalColor);
            viewIncomeDivider.setVisibility(View.GONE);
            tvApplicationRecord.setTextColor(selectedColor);
            viewApplicationDivider.setVisibility(View.VISIBLE);
        }
        viewPager.setCurrentItem(currentItem);
    }

    @OnClick({R.id.rl_income_record,R.id.rl_application_record})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.rl_income_record:
                setCurrentPage(PAGE_INCOME_RECORD);
                break;
            case R.id.rl_application_record:
                setCurrentPage(PAGE_APPLICATION_RECORD);
                break;
        }
    }
}
